import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
// jdbc入门
public class Test00 {
    public static void main(String[] args) throws Exception{
//        1. 加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
//        2. 建立连接
        Connection connection = DriverManager.getConnection
                ("jdbc:mysql://192.168.56.101:3306/itcast_shop","root","1234");
//        3. 基本操作
//        获取sql语句对象
        Statement statement = connection.createStatement();
//        编写SQL查询语句
        String sql = "select * from itheima_goods";
//        提交SQL查询语句
        ResultSet set = statement.executeQuery(sql);
//        遍历结果集
        while (set.next()) {
            System.out.print(set.getInt("goodsId")+", ");
            System.out.println(set.getString("goodsName"));
        }
//        4.释放资源
//        先开的后关，后开的先关
        set.close();
        statement.close();
        connection.close();
    }
}
